package com.smart.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.manage.domain.DrugIncoming;
import com.smart.manage.service.IDrugIncomingService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 药品入库信息Controller
 * 
 * @author lingyao
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/manage/drugIncoming")
public class DrugIncomingController extends BaseController
{
    @Autowired
    private IDrugIncomingService drugIncomingService;

    /**
     * 查询药品入库信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:drugIncoming:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugIncoming drugIncoming)
    {
        startPage();
        List<DrugIncoming> list = drugIncomingService.selectDrugIncomingList(drugIncoming);
        return getDataTable(list);
    }

    /**
     * 导出药品入库信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:drugIncoming:export')")
    @Log(title = "药品入库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugIncoming drugIncoming)
    {
        List<DrugIncoming> list = drugIncomingService.selectDrugIncomingList(drugIncoming);
        ExcelUtil<DrugIncoming> util = new ExcelUtil<DrugIncoming>(DrugIncoming.class);
        util.exportExcel(response, list, "药品入库信息数据");
    }

    /**
     * 获取药品入库信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:drugIncoming:query')")
    @GetMapping(value = "/{incomingId}")
    public AjaxResult getInfo(@PathVariable("incomingId") Long incomingId)
    {
        return success(drugIncomingService.selectDrugIncomingByIncomingId(incomingId));
    }

    /**
     * 新增药品入库信息
     */
    @PreAuthorize("@ss.hasPermi('manage:drugIncoming:add')")
    @Log(title = "药品入库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugIncoming drugIncoming)
    {
        Long userId = getUserId();
        drugIncoming.setOperatorId(userId);
        return toAjax(drugIncomingService.insertDrugIncoming(drugIncoming));
    }

    /**
     * 修改药品入库信息
     */
    @PreAuthorize("@ss.hasPermi('manage:drugIncoming:edit')")
    @Log(title = "药品入库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugIncoming drugIncoming)
    {
        return toAjax(drugIncomingService.updateDrugIncoming(drugIncoming));
    }

    /**
     * 删除药品入库信息
     */
    @PreAuthorize("@ss.hasPermi('manage:drugIncoming:remove')")
    @Log(title = "药品入库信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{incomingIds}")
    public AjaxResult remove(@PathVariable Long[] incomingIds)
    {
        return toAjax(drugIncomingService.deleteDrugIncomingByIncomingIds(incomingIds));
    }
}
